////
//
/// \file ./include/inc/parser/mutation_node.hpp
//
//  Copyright 2007, 2008 Chandler Carruth
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations
//  under the License.
//
////

#ifndef inc_parser_mutation_node_header
#define inc_parser_mutation_node_header

#include <string>

#include <boost/scoped_ptr.hpp>

#include <inc/parser/parse_tree_node.hpp>
#include <inc/parser/ws_parser.hpp>

namespace inc {
namespace parser {

class ExpressionNode;
class LabelNode;
class SymbolNode;

/// \brief  Mutation Node
/// \author Chandler Carruth
/// \date   2007.06.2
///
/// This parses mutations, statement level infix binary and both prefix and
/// postfix unary "mutators", or operations which cause side effects.

class MutationNode : public ParseTreeNode
{
public:
  MutationNode();
  virtual ~MutationNode();

  virtual bool parse( const iterator& first,
                      const iterator& last,
                      iterator& last_parsed );

  virtual LabelNode* get_lhs_label() const;
  virtual LabelNode* get_rhs_label() const;
  virtual bool is_double_label() const { return get_lhs_label() != NULL; }

  virtual ExpressionNode* get_unary_expr() const;
  virtual bool is_unary_prefix() const;
  virtual bool is_unary_postfix() const;
  virtual bool is_unary() const
      { return get_unary_expr() != NULL || is_double_label(); }

  virtual ExpressionNode* get_lhs_expr() const;
  virtual ExpressionNode* get_rhs_expr() const;
  virtual bool is_binary() const { return !is_unary(); }

  virtual LabelNode* get_mut_label() const;
  virtual bool is_mut_label() const { return get_mut_label() != NULL; }

  virtual SymbolNode* get_mut_symbol() const;
  virtual bool is_mut_symbol() const { return get_mut_symbol() != NULL; }

private:
  /// \name Parsing Helper Routines
  //@{
  bool parse_rhs_expr( const iterator& first,
                       const iterator& last,
                       iterator& last_parsed );
  bool parse_prefix_symbol( const iterator& first,
                            const iterator& last,
                            iterator& last_parsed );
  bool parse_prefix_label( const iterator& first,
                           const iterator& last,
                           iterator& last_parsed );
  bool parse_label_label( const iterator& first,
                          const iterator& last,
                          iterator& last_parsed );
  bool parse_postfix_binary_label( const iterator& first,
                                   const iterator& last,
                                   iterator& last_parsed );
  bool parse_postfix_binary_symbol( const iterator& first,
                                    const iterator& last,
                                    iterator& last_parsed );
  bool parse_lhs_expr( const iterator& first,
                       const iterator& last,
                       iterator& last_parsed );
  //@}

  //  Parsing Helpers
  boost::scoped_ptr<WSParser> ws;

  //  Concrete Parse Results
  boost::scoped_ptr<LabelNode> mut_label;
  boost::scoped_ptr<SymbolNode> mut_symbol;

  boost::scoped_ptr<ExpressionNode> lhs_expr;
  boost::scoped_ptr<ExpressionNode> rhs_expr;

  //  Ambiguous Parse Results
  boost::scoped_ptr<LabelNode> lhs_label;
  boost::scoped_ptr<LabelNode> rhs_label;
};

} //  end parser namespace
} //  end inc namespace
#endif  //  _parser_mutation_node_header_
